﻿<?php
	session_start();
	require_once('../../lib/'.'BaseDir.inc.htm');	
	require_once('../../lib/'.'DBCommon.class.htm');
	
	
	$ModifiedBy = $_SESSION['userName'];		
	//print_r($ModifiedBy);
	$oDB = new DBCommon();
	$conn =  $oDB->stl_openConn();	
	
	$CATCode = $_POST["CATCode"];
	$AssName = $_POST["AssName"];
	$Price = $_POST["Price"];	
	$SellDate = date("Y-m-d");	
	$Quantity = 1;	
	$Unit = $_POST["Unit"];
	$PriceHistory = mysql_real_escape_string("{'DateChange':'".date("Y-m-d G-i-s")."','Price':'".$Price."'},");
	//var_dump($PriceHistory);exit();
	$q = "
		INSERT INTO price_tbl (CATCode,AssName,SellDate,Price,Quantity,Unit,CreateDate,ModifiedBy,PriceHistory) 
		VALUES ('".$CATCode."','".$AssName."','".$SellDate."','".$Price."','".$Quantity."','".$Unit."','CURRENT_TIMESTAMP','".$ModifiedBy."','".$PriceHistory."')
			ON DUPLICATE KEY UPDATE Price = '".$Price."', PriceHistory = CONCAT(PriceHistory,'".$PriceHistory."'),ModifiedBy = '".$ModifiedBy."';
	";	
	
	//echo $q;
	
	$rs_insert = $oDB->stl_db_change($q, $conn);
	
	if($rs_insert)
	{
		echo "OK";
	}
	else
	{
		echo "NG";
	}
	
	$oDB->stl_closeConn($conn);
	
?>
